//
//  MusicViewController.m
//  wAudioShare
//
//  Created by 赵帅 on 14-1-9.
//  Copyright (c) 2014年 赵帅. All rights reserved.
//

#import "MusicViewController.h"
#import "USBMusicViewController.h"
#import "LocalMusicViewController.h"
#import "RadioViewController.h"

@interface MusicViewController ()
{
    
}

@end

@implementation MusicViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - tab methods
- (NSString *)tabImageName
{
	return @"TAB_ICON_2.png";
}

- (NSString *)tabTitle
{
	return NSLocalizedString(@"MUSIC_PLAY",@"");
}

#pragma mark - navigation methods
-(NSString *)navigationBarTitle
{
    return NSLocalizedString(@"MUSIC_PLAY",@"");
}

-(BOOL)isNewVersionButtonEnabled
{
    return YES;
}

-(IBAction)backButtonPressed:(id)sender
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"PopTabBarController" object:self];
}

#pragma mark -
#pragma mark UITableView Delegate & Datasource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier];
    }
    else
    {
        for(UIView * subview in [cell.contentView subviews])
        {
            [subview removeFromSuperview];
        }
    }
    
    // Configure the cell.
    
    UIImage * image = nil;
    UILabel * label = [[UILabel alloc] init];

    if(indexPath.row == 0)
    {
        image = [UIImage imageNamed:@"music_usb"];
        label.text = NSLocalizedString(@"USB_MUSIC",@"");
    }
    else if(indexPath.row == 1)
    {
        image = [UIImage imageNamed:@"music_local"];
        label.text = NSLocalizedString(@"LOCAL_MUSIC",@"");
    }
    else if(indexPath.row == 2)
    {
        image = [UIImage imageNamed:@"music_radio"];
        label.text = NSLocalizedString(@"RADIO_MUSIC",@"");
    }
    
    UIImageView * imageview = [[UIImageView alloc] initWithImage:image];
    [cell.contentView addSubview:imageview];
    [imageview setFrame:CGRectMake(10, 10, 40, 40)];

    label.backgroundColor = [UIColor clearColor];
    label.frame = CGRectMake(60, 10, 200, 40);
    [cell.contentView addSubview:label];
    
    UIImageView * rightImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"rightarrow1.png"]];
    rightImage.frame = CGRectMake(tableView.frame.size.width-40, 20, 10, 20);
    [cell.contentView addSubview:rightImage];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:YES];
    
    if(indexPath.row == 0)
    {
        USBMusicViewController * controller = [[USBMusicViewController alloc] initWithNibName:@"USBMusicViewController" bundle:nil];
        [self.navigationController pushViewController:controller animated:YES];
    }
    else if(indexPath.row == 1)
    {
        LocalMusicViewController * controller = [[LocalMusicViewController alloc] initWithNibName:@"LocalMusicViewController" bundle:nil];
        [self.navigationController pushViewController:controller animated:YES];
    }
    else if(indexPath.row == 2)
    {
        RadioViewController * controller = [[RadioViewController alloc] initWithNibName:@"RadioViewController" bundle:nil];
        [self.navigationController pushViewController:controller animated:YES];
    }
}

@end
